﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrainStation.TrainModules;
using TrainStation.Tracks;

namespace TrainStation
{
    class TrainModel
    {
        RailRoad railRoad;
        Train train;
        Dispatcher dispatcher;
        public TrainModel()
        {
            train = new Train();
            train.AddWagon(new PassengerWagon());
            train.AddWagon(new PassengerWagon());

            railRoad = new RailRoad(train);
            GenerateTrack();
            railRoad.StartTrains();

            train.CurrentTrack = railRoad.Road;

            dispatcher = new Dispatcher(railRoad);
            dispatcher.Start();
        }

        void GenerateTrack()
        {
            LineTrack startTrack = new LineTrack();

            ITrack previous = startTrack;
            ITrack next;
            for (int i = 0; i < 3; i++)
            {
                next = new LineTrack();
                previous.Next = next;
                next.Previous = previous;
                previous = next;
            }

            previous.Next = startTrack;
            railRoad.Road = startTrack;
        }
    }
}
